﻿/**
 * @author sminutoli
 * version 1.0
 * revisar el tema del intervalo para ver cuantos eventos dispachea
 * se agrega una propiedad "active" que sirve para bloquear el estado del botón
 */
 
import com.dinmax.flash.draw.cabeza.ControlCabeza

class com.dinmax.flash.draw.cabeza.ButtonCabeza
extends ControlCabeza {
	
	private static var DISABLED:String="disabled";
	private static var ENABLED:String="enabled";
	private static var ROLLOVER:String="onRollOver";
	private static var ONPRESS:String="onPress";
		
	private var nIntervalPressID:Number;
	private var active:Boolean;
	private var nIntervalDuration:Number;
	private var txt_label:TextField;
		
	public function onLoad():Void{
		
		var parent:ControlCabeza = ControlCabeza(this._parent);
		if(parent) parent.initChild(this);
	};
	
	public function getActive():Boolean {
		return this.active;
	};
	
	public function setActive(active:Boolean):Void {
		this.active = active;
		if(this.active){
			this.gotoAndStop(ButtonCabeza.ONPRESS);
		} else {
			this.gotoAndStop(ButtonCabeza.ENABLED);
		}
		return;
	};
	
	public function setLabel(label:String):Void {
		this.txt_label.text = label;
		return;
	};
	
	public function getLabel():TextField {
		return this.txt_label;
	};
	
	public function onPress():Void{
		//trace("ButtonCabeza.as | onPress()");
		this.gotoAndStop(ButtonCabeza.ONPRESS);
		this.selectEvent();
		if(this.nIntervalDuration != undefined){
			nIntervalPressID = setInterval(this, "change", this.nIntervalDuration);
		};
		
		return;
	};
	
	public function onRelease():Void{
		//trace("ButtonCabeza.as | onRelease()");
		if(!this.active) this.onRollOver();
		clearInterval(nIntervalPressID);
		
		return;
	};
	
	public function onReleaseOutside():Void{
		if(!this.active) {
			this.onRelease();
			this.onRollOut();
		}
		return;
	};
	
	public function onRollOver():Void {
		//trace("ButtonCabeza.as | onRollOver");
		if(!this.active) this.gotoAndStop(ButtonCabeza.ROLLOVER);
		return;
	};
	
	public function onRollOut():Void {
		//trace("ButtonCabeza.as | onRollOut");
		if(!this.active) this.gotoAndStop(ButtonCabeza.ENABLED);
		return;
	};
	
	public function setDisabled():Void{
		//trace("ButtonCabeza.as | setDisabled()");
		this.gotoAndStop(ButtonCabeza.DISABLED);
		this.enabled = false;
		return;
	};
	
	public function setEnabled():Void {
		//trace("ButtonCabeza.as | setEnabled()");
		if(!this.active) this.gotoAndStop(ButtonCabeza.ENABLED)
		else this.gotoAndStop(ButtonCabeza.ONPRESS);
		this.enabled = true;
		return;
	};
			
	public function setIntervalDuration(duration:Number):Void{
		this.nIntervalDuration = duration;
		return;
	};
}
